package com.example.image_steganography_library_master.slice;

import com.example.image_steganography_library_master.Decode;
import com.example.image_steganography_library_master.Encode;
import com.example.image_steganography_library_master.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;

public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        Button encode = (Button) findComponentById(ResourceTable.Id_encode_button);
        Button decode = (Button) findComponentById(ResourceTable.Id_decode_button);
        encode.setClickedListener(this::onClick);
        decode.setClickedListener(this::onClick);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    private void  startAbilitys(String toPages) {
        Intent secondIntent = new Intent();
        // 指定待启动FA的bundleName和abilityName
        Operation operation = new Intent.OperationBuilder()
                .withDeviceId("")
                .withBundleName(getAbilityPackageContext().getBundleName())
                .withAbilityName(toPages)
                .build();
        secondIntent.setOperation(operation);
       startAbility(secondIntent);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_encode_button:
                startAbilitys(Encode.class.getName());
                break;
            case ResourceTable.Id_decode_button:
                startAbilitys(Decode.class.getName());
                break;
            default:
        }
    }
}
